<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <fredbird@fredbird.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* Triggers pile : triggers to be ran.
* @author J.Ducastel <fredbird@fredbird.org>
* @version 
*/
class wakTriggersPile {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	*/
	function wakTriggersPile() {
		$this->__construct();
	}/**/
	
	/**
	*
	* @access
	*/
	function __construct() {
		//parent::__construct();
		//$lib=&wak::getservice('waklib');
		//$lib->needclass('wakpile');
		$this->piles[1]=&new wakpile('desc');
		$this->piles[2]=&new wakpile('desc');
		$this->piles[3]=&new wakpile('desc');
		$this->piles[4]=&new wakpile('desc');
		$this->piles[5]=&new wakpile('desc');
		$this->piles[6]=&new wakpile('desc');
		$this->piles[7]=&new wakpile('desc');
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* inserts a trigger into pile
	* @param wakTrigger $trigger
	* @access public
	* @return 
	*/
	function addTrigger(&$trigger) {
		$step=$trigger->getMember('step');
		$position=$trigger->getMember('priority');
		return $this->piles[$step]->insert($trigger,$position);
	}/**/
	
	/**
	* shift item from step's pile
	* @param itn $step
	* @access public
	* @return wakTrigger|false
	*/
	function & shift($step) {
		$pile=&$this->piles[$step];
		$shifted=&$pile->shift();
		return $shifted;
	}/**/
	
	/**
	* returns pile's content as a text list
	* @param
	* @access public
	* @return string
	*/
	function dumpAsText() {
		$dump='triggers pile dump : ';
		//$deb=wak::getservice('wakdebug');
		for ($step=1; $step<=7; $step++) {
			$pileContent=$this->piles[$step]->dump();
			//echo $deb->vardump($pileContent);
			foreach ($pileContent as $trigger) {
				
				$dump.=$trigger->getStep().':'.$trigger->getPriority()
				.'|'.$trigger->getEventCall().' ';
			}
		}
		return $dump;
	}/**/
	
	/**
	* clears (empties) step's pile, or all piles
	* @param
	* @access public
	* @return bool
	*/
	function clear($step=null) {
		if (is_int($step)) {
			// clearing pile
			return $this->piles[$step]->clear();
		} else {
			// clearing all
			for ($step=1; $step<=7; $step++)
				if (!$this->piles[$step]->clear())
					return false;
			return true;
		}
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var type desc
	*/
	var $piles=array(); // triggers piles, 1 per step
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
